package com.lagou.edu.service.impl;

import com.lagou.edu.annotation.Autowired;
import com.lagou.edu.annotation.Service;
import com.lagou.edu.annotation.Transactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;

/**
 * @author taoxiaoyin
 */
@Service(value ="transferService")
@Transactional
public class TransferServiceImpl implements TransferService {
    /**
     * @Author 陶肖寅
     * @Description //注入accountDao
     * @Date 11:43 2020/1/14
     * @Param
     * @return
     **/
    @Autowired
    AccountDao accountDao;


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);
            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);
            accountDao.updateAccountByCardNo(to);
            accountDao.updateAccountByCardNo(from);
    }

    @Override
    public void test() {
        System.out.println("测试service");
        accountDao.add();
    }
}
